import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { School } from './school.entity';
import { Gateway } from './gateway.entity';
import { Student } from './student.entity';

@Entity('class')
export class ClassEntity {
  @PrimaryGeneratedColumn('increment')
  id: number;

  @ManyToOne(() => School, { onDelete: 'NO ACTION', onUpdate: 'NO ACTION' })
  @JoinColumn({ name: 'school_id' })
  school: School;

  @Column({ type: 'varchar', length: 255, default: '' })
  name: string;

  @Column({ type: 'varchar', length: 255, default: '' })
  photo: string;

  @OneToMany(() => Gateway, (gateway) => gateway.class)
  gateways: Gateway[];


  // 在 ClassEntity 中应该有对应的反向关系
  @OneToMany(() => Student, (student) => student.class)
  students: Student[];
}
